package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:泛型方法
 * User: cjc
 * Date: 2025-04-13
 * Time: 10:10
 */
class Swap {
    public static <T> void swap(T[] array, int i,int j) {
        T temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}
public class Test<T> {
    private static<T> void printArray(T[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }

    public T find(T[] array,int pos) {
        return array[pos];
    }

    public static void main(String[] args) {
        Integer[] intArray = {1,2,3,4,5};
        Swap.swap(intArray,2,3);
        printArray(intArray);
        System.out.println("=====");
        String[] stringArray = {"Hello","World"};
        Swap.swap(stringArray,0,1);
        printArray(stringArray);
        System.out.println("=====");
        Test<Integer> integerTest = new Test<>();
        System.out.println(integerTest.find(intArray, 4));
    }
}
